import config from "@/utils/config.js"

function get(obj = {
	url,
	data
}) {
	return _req(obj)
}

function post(obj = {
	url,
	data
}) {
	obj.method = "POST"
	return _req(obj)
}

function _req({
	url,
	data = {},
	method = "GET",
}) {
	// 使用Promise进行异步管理
	return new Promise((resolve, reject) => {
		uni.request({
			url: config.bashUrl + url,
			data: data,
			method: method == "GET" ? "GET" : "POST",
			header: {
				"content-type": method == "GET" ? "application/json" :
					"application/x-www-form-urlencoded"
			},
			success(res) {
				resolve(res.data);
			},
			fail(e) {
				reject(e)
			}
		})
	})

}

export default {
	get,
	post
}
